#include "StdAfx.h"
#include "ModelEditorEx.h"


CModelEditorEx::CModelEditorEx(void)
{
}

CModelEditorEx::~CModelEditorEx(void)
{
}

Handle(TColgp_HArray1OfPnt) CModelEditorEx::GetPointArrary()
{
	Handle(TColgp_HArray1OfPnt) ptArr = new TColgp_HArray1OfPnt(1, m_ptList.size());
	PointList::iterator it = m_ptList.begin();
	for(int i=1; it!=m_ptList.end(); ++it,++i)
	{
		ptArr->SetValue(i, *it);
	}

	return ptArr;
}

void CModelEditorEx::Initialize(CAnyView* pView)
{
	CModelEditor::Initialize(pView);

	m_ptList.clear();
}

EditorState CModelEditorEx::OnLButtonDown(UINT nFlags, long x, long y)
{
	gp_Pnt point;
	GetView()->ConvertToGrid(x,y, point);
	if(m_ptList.size()>1)
	{
		PointList::reverse_iterator it = m_ptList.rbegin();
		if(!point.IsEqual(*it, 0.01))
			m_ptList.push_back(point);
		Preview();
	}
	else
	{
		m_ptList.push_back(point);
	}

	return ES_CONTINUE;
}
void CModelEditorEx::OnMouseMove(UINT nFlags, long x, long y)
{
	gp_Pnt point;
	GetView()->ConvertToGrid(x,y, point);
	if(m_ptList.size()>0)
	{
		m_ptList.push_back(point);
		Preview();
		m_ptList.pop_back();
	}
}
EditorState CModelEditorEx::OnRButtonDown(UINT nFlags, long x, long y)
{
	gp_Pnt point;
	GetView()->ConvertToGrid(x,y, point);
	m_ptList.push_back(point);

	Finish();
	Initialize(GetView());

	return ES_CONTINUE;
}